<template>
	<view class="wrap">
		<view class="top"></view>
		<view class="content">
			<view class="title">欢迎登录久富商城</view>
			<!-- <view class="tips">未注册的手机号自动创建久富商城账号</view> -->
			<view class="hint">
				<checkbox-group @change="checkboxChange">
					<checkbox style="transform: scale(0.6,0.6);" ></checkbox>
				<text>阅读并同意</text>
				<text class="link" @click="goPage('/pages/login/userProtocol')">久富商城用户协议</text>、
				<text class="link" @click="goPage('/pages/login/privateProtocol')">隐私政策，</text>
				并授权使用您的久富商城账号信息（如昵称、头像、收获地址）以便您统一管理
				</checkbox-group>
			</view>
			<br>
			<button :style="[inputStyle]" type="warn" open-type="getPhoneNumber" :disabled="buttonDisabled"
				@getphonenumber="getPhoneNumber">手机号快捷登录</button>
			<view class="alternative">
				<view class="password" @click="passwordLogin">密码登录</view>
				<view class="issue">遇到问题</view>
			</view>
		</view>

<!-- 		<view class="bottom">
			<view class="loginType">
			</view>
			<view class="hint">
				登录代表同意
				<text class="link" @click="goPage('/pages/login/userProtocol')">久富商城用户协议</text>、
				<text class="link" @click="goPage('/pages/login/privateProtocol')">隐私政策，</text>
				并授权使用您的久富商城账号信息（如昵称、头像、收获地址）以便您统一管理
			</view>
		</view> -->
	</view>
</template>

<script>
	export default {
		data() {
			return {
				tel: '',
				buttonDisabled: true
			}
		},
		computed: {
			inputStyle() {
				let style = {};
				if (this.tel && this.tel.length == 11 && this.tel.startsWith('1')) {
					style.color = "#fff";
					style.backgroundColor = this.$u.color['warning'];
				}
				return style;
			}
		},
		onLoad() {},
		methods: {
			checkboxChange(e){
				if(e.detail.value.length > 0){
					this.buttonDisabled = false
				}else{
					this.buttonDisabled = true
				}
				console.log('e',e)
				console.log("this.buttonDisabled",this.buttonDisabled)
			},
			getPhoneNumber(e) {
				console.log("this.hintCheck",this.hintCheck)
				console.log("e",e)
				let phoneCode = e.detail.code
				if (!e.detail.code) { }else{
					uni.login({
						provider: 'weixin',
						success: res =>{
							console.log("res",res)
							this.$u.get('/loginOrRegByWx?code='+res.code + '&phoneCode='+phoneCode + '&appId=wx6c24164fff67b245')
							.then(res => {
								 console.log("res",res)
								 console.log("wx",wx)
								 uni.clearStorageSync()
								 this.$u.vuex('vuex_token', res.token)
								 this.$u.vuex('vuex_user', res.user)
								 //优先展示手动上传的头像
								 if (res.user.avatar && res.user.avatar !== '') {
								 	this.$u.vuex('vuex_avatar', this.baseApi + '/file/getImgStream?idFile=' + res.user.avatar);
								 } else {
								 	if (res.user.wechatHeadImgUrl && res.user.wechatHeadImgUrl !== '') {
								 		//如果拉取到用户微信头像，则展示微信头像
								 		this.$u.vuex('vuex_avatar', res.user.wechatHeadImgUrl)
								 	}
								 }
								 
								 this.$u.route({
								 	type: 'switchTab',
								 	url: '/pages/user/profile'
								 })
							})
						}
					}) 
				} 
			},

			submit() {
				console.log("dsfsdfsd")
				if (!(this.tel && this.tel.length == 11 && this.tel.startsWith('1'))) {
					this.$u.toast('请输入正确手机号');
					return;
				}
				this.$u.post('sendSmsCode?mobile=' + this.tel).then(response => {
					this.$u.route({
						url: '/pages/login/smsCode',
						params: {
							mobile: this.tel,
							result: response
						}
					})
				})
			},
			loginBy(type) {
				this.$u.toast('第三方账号登录开发中，敬请期待')
			},
			goPage(url) {
				this.$u.route({
					url: url
				})
			},
			passwordLogin() {
				this.$u.route({
					url: '/pages/login/passwordLogin'
				})
			},
		}
	};
</script>

<style lang="scss" scoped>
	.wrap {
		font-size: 28rpx;

		.content {
			width: 600rpx;
			margin: 0 auto;
			padding-top: 80rpx;

			.title {
				text-align: center;
				font-size: 60rpx;
				font-weight: 500;
				margin-bottom: 100rpx;
			}

			input {
				text-align: left;
				margin-bottom: 10rpx;
				padding-bottom: 6rpx;
			}

			.tips {
				color: $u-type-info;
				font-size: 20rpx;
				margin-bottom: 60rpx;
				margin-top: 30rpx;
			}

			.getSmsCode {
				background-color: rgb(253, 243, 208);
				color: $u-tips-color;
				border: none;
				font-size: 30rpx;
				padding: 12rpx 0;

				&::after {
					border: none;
				}
			}

			.alternative {
				color: $u-tips-color;
				display: flex;
				justify-content: space-between;
				margin-top: 30rpx;
			}
			
			.hint {
				padding: 20rpx 20rpx;
				font-size: 20rpx;
				color: $u-tips-color;
				margin-bottom: 20rpx;
				.link {
					color: $u-type-warning;
				}
			}
		}

		.bottom {
			.loginType {
				display: flex;
				padding: 260rpx 150rpx 150rpx 150rpx;
				justify-content: space-between;

				.item {
					display: flex;
					flex-direction: column;
					align-items: center;
					color: $u-content-color;
					font-size: 28rpx;
				}
			}

			.hint {
				padding: 20rpx 40rpx;
				font-size: 20rpx;
				color: $u-tips-color;

				.link {
					color: $u-type-warning;
				}
			}
		}
	}
</style>